local xieshu = fk.CreateSkill {
  name = "ls__xieshu",
  tags = {"Phase"},
}

Fk:loadTranslationTable{
  ["ls__xieshu"] = "挟术",
  [":ls__xieshu"] = "阶段技，你可视为使用<a href=':lvshi__befriendattacking'>【远交近攻】</a>，然后你与目标角色拼点，若你没赢，你对一名己方角色造成1点伤害。",
  ["#ls__xieshu-choose"] = "挟术：请对一名己方角色造成1点伤害",

  ["$ls__xieshu1"] = "功高名盛，安得善终，唯自立也！",
  ["$ls__xieshu2"] = "算无遗策，晋道克昌，皆吾之力也！",
}

local ls = require "packages/lvshi/utility"

xieshu:addEffect("viewas", {
  pattern = "lvshi__befriendattacking",
  card_filter = Util.FalseFunc,
  view_as = function(self, player, cards)
    if #cards ~= 0 then return nil end
    local card = Fk:cloneCard("lvshi__befriendattacking")
    card.skillName = xieshu.name
    return card
  end,
  enabled_at_play = function(self, player)
    return player:usedSkillTimes(xieshu.name, Player.HistoryPhase) == 0
  end,
  enabled_at_response = Util.FalseFunc,
  after_use = function (self, player, use)
    local to = use.tos[1]
    if not to.dead then
      local pindian = player:pindian({to}, self.name)
      if pindian.results[to].winner and pindian.results[to].winner == player then
      else
        local result = player.room:askToChoosePlayers(player, {
          targets = table.filter(player.room:getAlivePlayers(), function (p)
            return ls.isFriend(player, p)
          end),
          min_num = 1,
          max_num = 1,
          prompt = "#ls__xieshu-choose",
          skill_name = xieshu.name,
          cancelable = false,
        })
        if #result > 0 then
          player.room:damage({
            from = player,
            to = result[1],
            damage = 1,
            damageType = fk.NormalDamage,
            skillName = xieshu.name,
          })
        end
      end
    end
  end,
})

return xieshu